const config = require('../../../config/config.local');
const amazonMws = require('amazon-mws')(config.AWSAccessKeyId, config.AWSSecretKey);
// const isProduction = process.env.NODE_ENV === 'production';

const d = {};

d.submitFeed = function (seller_id, mws_auth_token, feedType, feedContent, marketplaceIdList=null, purgeAndReplace=null) {
  let baseOption = {
    'Version': '2009-01-01',
    'Action': 'SubmitFeed',
    'SellerId': seller_id,
    'MWSAuthToken': mws_auth_token,
    'FeedType': feedType,
    'FeedContent': feedContent
  };
  if (marketplaceIdList){
    let keyPrefix = "MarketplaceIdList.Id";
    marketplaceIdList.forEach((item, index) => {
      baseOption[keyPrefix + "." + (index+1)] = item;
    });
  }
  if (purgeAndReplace){
    baseOption["PurgeAndReplace"] = purgeAndReplace;
  }

  return amazonMws.feeds.submit(baseOption);
};

module.exports = d;